<%- include('../public/page_header.html')%>
<script src="/jqPaginator/jq-paginator.js"></script>
<div class="panel panel-default">
  <div class="panel-heading">
      <a href="/<%=adminPath%>/article/add" class="btn btn-primary">增加内容</a>
  </div>
  <div class="table-responsive">
      <table class="table table-bordered">
          <thead>
              <tr class="th">
                  <th class="text-center">名称</th>
                  <th class="text-center">分类</th>
                  <th class="text-center">图片</th>
                  <th class="text-center">排序</th>
                  <th class="text-center">状态</th>
                  <th class="text-center">操作</th>
              </tr>
          </thead>
          <tbody>
            <% for(let i=0; i<list.length; i++){%>
                <tr>
                    <td class="text-center">
                      <span  class="chSpanNum" data-id="<%=list[i]._id%>" data-model="Article" data-field="title">
                        <%=list[i].title%>
                      </span>
                    </td>
                    <td class="text-center">
                        <%=list[i].cate[0].title%>
                    </td>
                    <td class="text-center">
                      <% if(list[i].article_img){%>
                        <img src="\<%=list[i].article_img%>" width="80px" alt="">
                      <%}%>
                    </td>
                    <td class="text-center">
                      <span class="chSpanNum" data-id="<%=list[i]._id%>" data-model="Article" data-field="sort">
                        <%=list[i].sort%>
                      </span>
                    </td>
                    <td class="text-center">
                      <% if(list[i].status == 1){%>
                        <img src="/admin/images/yes.png" class="chStatus" data-id="<%=list[i]._id%>" 
                             data-model="Article" data-field="status">
                      <%}else{%>
                        <img src="/admin/images/no.png"  class="chStatus" data-id="<%=list[i]._id%>"
                             data-model="Article" data-field="status">
                      <%}%>
                    </td>
                    <td class="text-center">
                        <a href="/<%=adminPath%>/article/edit?id=<%=list[i]._id%>">修改</a>
                        <a class="delete" href="/<%=adminPath%>/article/delete?id=<%=list[i]._id%>">删除</a>
                    </td>
                </tr>
            <%}%>
          </tbody>
      </table>
  </div>
</div>
<div class="pagination" id="pagination"></div>

<script>
  $('#pagination').jqPaginator({
    totalPages: <%=totalPages%>,
    visiblePages: 5,
    currentPage: <%=page%>,
    onPageChange: function (num, type) {
      if(type == 'change'){
        location.href= `/<%=adminPath%>/article?page=`+num;
      }
    }
});
</script>
</body>
</html>